package regulation.auto.com.request;

import android.content.Context;

import com.ptjob.basecore.bean.ClientDataHull;
import com.ptjob.basecore.exception.ErrorCode;

import regulation.auto.com.api.AtuoRegulationHttpApi;
import regulation.auto.com.bean.PointBean;
import regulation.auto.com.parser.PointParser;

/**
 * Created by lidongming on 2016/10/19.
 */

public class RequestPointsTask extends AbstractAsyncTask<PointBean> {
    private AsyncCallBack mAsyncCallBack;


    public RequestPointsTask(Context context, AsyncCallBack mAsyncCallBack) {
        super(context);
        this.mAsyncCallBack = mAsyncCallBack;
    }

    @Override
    public ClientDataHull<PointBean> doInBackground() {
        return AtuoRegulationHttpApi.pointRequestTask(new PointParser());
    }

    @Override
    public void onPostExecute(int updateId, PointBean result) {
        if(result != null){
            if(mAsyncCallBack != null){
                mAsyncCallBack.update(result);
            }
        } else {
            if(mAsyncCallBack != null){
                mAsyncCallBack.dataError(ErrorCode.DATA_REQUEST_NULL, null);
            }
        }
    }
    @Override
    public void netNull() {
        if(mAsyncCallBack != null){
            mAsyncCallBack.dataError(ErrorCode.NETWORK_NOT_AVAILABLE, null);
        }
    }

    @Override
    public void netErr(int updateId, String errMsg) {
        if(mAsyncCallBack != null){
            mAsyncCallBack.dataError(ErrorCode.NETWORK_REQUEST_ERROR, errMsg);
        }
    }

    @Override
    public void dataNull(int updateId, String errMsg) {
        if(mAsyncCallBack != null){
            mAsyncCallBack.dataError(ErrorCode.DATA_REQUEST_NULL, errMsg);
        }
    }


}
